/*
********************
    根类Object
********************
*/

#ifndef COOL_OBJECT_H_
#define COOL_OBJECT_H_

#include <stdio.h>
#include <stdlib.h>

//  前向声明
typedef struct Object Object;
typedef struct ClassInfo ClassInfo;

//  类型信息
struct ClassInfo {
    const char* name;
    const ClassInfo* super;
    size_t instance_size;
}

//  虚函数表
typedef struct ObjectVTable {
    void (*destroy)(Object* self);
    const char* (*tostring)(Object* self);
} ObjectVTable;

//  根类
struct Object {
    const ObjectVTable* vptr;
    const ClassInfo* clazz;
    int ref_cout;
}

//  全局函数
void Object_destroy(Object* self);
const char* Object_tostring(Object* self);
//  是否是指定类型的实例
int instanceof(const Object* obj, const ClassInfo* type);
const ClassInfo* get_class(const Object* obj);
//  增加引用计数
Object* ratain(Object* obj);
void release(Object* self);

#endif